﻿namespace ImageWallControl.BrushProviders
{
    using System;
    using System.Collections.Generic;
    using System.Windows.Media;
    using Random = ImageWallControl.Random;

    public class RandomColorBrushProvider : IBrushProvider
    {
        public void Initialize(Action<IEnumerable<Brush>> afterInitialize)
        {
            afterInitialize(Brushes());
        }

        public Brush GetBrush()
        {
            var color = new Color
                            {
                                A = 0xff,
                                R = (byte) Random.Generator.Next(0, 255),
                                G = (byte)Random.Generator.Next(0, 255),
                                B = (byte)Random.Generator.Next(0, 255)
                            };
            return new SolidColorBrush(color);
        }

        private IEnumerable<Brush> Brushes()
        {
            while (true)
                yield return GetBrush();
        }
    }
}